package src.com.unapec.seguridad.login.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class BDManager {

	private SecurityConnection sc = new SecurityConnection(); 

	public void write(String username, String password){

		try {

			sc.connect();
			Statement statement = sc.getConnection().createStatement();
			statement.execute("Update Login set password="+"\'"+password+"\' where id = "+"\'"+username+"\';");

		} catch (SQLException e) {

			e.printStackTrace();

		}

		sc.disconnect();

	}

	public String getPassword(String username){

		String password = null;
		
		try {

			sc.connect();
			Statement statement = sc.getConnection().createStatement();
			ResultSet rs = statement.executeQuery("Select password from Login where id = "+"\'"+username+"\';");
			
			while(rs.next()){
			
			password = rs.getString("password");
			
			}
			
			
		} catch (SQLException e) {

			e.printStackTrace();

		}

		sc.disconnect();
		return password;
		
	}
	
	public ResultSet getData(){
		
		ResultSet rs = null;
		
		try {

			sc.connect();
			Statement statement = sc.getConnection().createStatement();
			rs = statement.executeQuery("Select * from EncryptExample");
			
			
		} catch (SQLException e) {

			e.printStackTrace();

		}

		sc.disconnect();
		return rs;

		
	}

	



}
